﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpVectors.Converters;
using System.Windows.Media;

namespace GG.Base
{
    public static class SvgUtils
    {
        public static FileSvgReader reader;

        public static Drawing getDrawingFromSvg(String url)
        {
            if (reader == null)
            {
                SharpVectors.Renderers.Wpf.WpfDrawingSettings settings = new SharpVectors.Renderers.Wpf.WpfDrawingSettings();
                settings.IncludeRuntime = false;
                settings.TextAsGeometry = true;
                reader = new FileSvgReader(settings);
            }
            DrawingGroup topGroup = reader.Read(url);
            DrawingGroup group = (DrawingGroup) topGroup.Children[0];
            RectangleGeometry rectGeom = group.ClipGeometry as RectangleGeometry;
            rectGeom.Transform = new TranslateTransform(-rectGeom.Rect.Right / 2, -rectGeom.Rect.Bottom / 2);
            return group;
        }
    }
}
